﻿using DevExpress.Diagram.Core;
using DevExpress.XtraDiagram;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace B.MESUI.Login.A_Public.自定义工作流
{
    public partial class WorkflowDesignerForm : DevExpress.XtraEditors.XtraForm
    {

        public WorkflowDesignerForm()
        {
            InitializeComponent();

            // 右键菜单添加节点
          
            diagramControl1.ContextMenuStrip = new ContextMenuStrip();
            diagramControl1.ContextMenuStrip.Items.Add("添加节点", null, (s, e) =>
            {
                var pt = diagramControl1.PointToClient(Cursor.Position);
                // 23.1版本 DiagramControl 有 ClientToDiagram 方法
                // 试试能否找到 ClientToDiagram
                //var methods = typeof(DevExpress.XtraDiagram.DiagramControl).GetMethods();
                //foreach (var m in methods)
                //{
                //    MessageBox.Show(m.Name);
                //}

                //var diagramPoint = diagramControl1.ClientToDiagram(pt);
                //var shape = new DevExpress.XtraDiagram.DiagramShape()
                //{
                //    Position = diagramPoint,
                //    Size = new SizeF(100, 60),
                //    Content = "新节点"
                //};
                //diagramControl1.Items.Add(shape);

            });
        }

        private void diagramControl1_Click(object sender, EventArgs e)
        {

        }

        private void WorkflowDesignerForm_Load(object sender, EventArgs e)
        {
           
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog dlg = new SaveFileDialog() { Filter = "XML文件|*.xml" })
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    diagramControl1.SaveDocument(dlg.FileName);
                    XtraMessageBox.Show("保存成功！");
                }
            }
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog() { Filter = "XML文件|*.xml" })
            {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    diagramControl1.LoadDocument(dlg.FileName);
                    XtraMessageBox.Show("加载成功！");
                }
            }
        }

    }
}